function LoginCtrl($scope, $http, $location,$route,UserFactory) {
	$scope.showAlertErrorLogin = false;
	$scope.waitingLogin = false;
	$scope.loginButton = true;
	$scope.userAdmin = false;
	
	$scope.loginUser = function(){
		$scope.showAlertErrorLogin = false;
		var user =  $("#login-user").val();
		var pass =  $("#login-password").val();
		if(pass && user){
			UserFactory.setUsername(user);
			UserFactory.setPassword(pass);
			$scope.userAdmin = user == 'admin' ? true : false;
			$scope.loginButton = false;
			$scope.waitingLogin = true;
			$scope.showAlertErrorLogin = false;
			var url = '../certh';
	        $http.post(url,UserFactory.getUser()).
	        	success(function(data){
                    $.cookie('coti', base64_encode(user), { expires: 5, path: '/'});//expires in 5 days
                    $location.path("/home");
	        	}).error(function(){
	        	   $("#loginError").children("p").html("Username and/or Password are incorrect.");
	    		   $scope.showAlertErrorLogin = true;
	    		   $scope.waitingLogin = false;
	    		   $scope.loginButton = true;
	        	})
		}
	};
}